package com.client.login.mobile.action;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class HttpClientTest {
	public static void main(String[] args) {
		try{
			 HttpClient client = new HttpClient();
			 PostMethod method = new PostMethod("http://218.26.20.252:8088/login/login.do");
			 NameValuePair requestData = new NameValuePair("requestData","{\"userCode\":\"010130\",\"password\":\"010130\"}");
			 method.setRequestBody(new NameValuePair[] {requestData});
			 client.executeMethod(method);
			 String response = new String(method.getResponseBody(),"UTF-8");
			 Cookie[] cookies =  client.getState().getCookies();
			 //System.out.println(response);
			 
			 //A new client
			 HttpClient client1 = new HttpClient();
			 HttpState state = new HttpState();
			 state.addCookies(cookies);
			 client1.setState(state);
			 PostMethod method1 = new PostMethod("http://218.26.20.252:8088/report/listGoodsSaleDeptDtl.do");
			 NameValuePair requestData1 = new NameValuePair("requestData","{\"conditionData\":{},\"specialCondition\":null,\"currentPage\":1}");
			 method1.setRequestBody(new NameValuePair[] {requestData1});
			 client1.executeMethod(method1);
			 response = new String(method1.getResponseBody(),"UTF-8");
			 
			 System.out.println(response);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
